<template>
    <view class="page-container">
        <!-- 顶部图片区域 -->
        <view class="top-image-section" :style="{ backgroundImage: `url(${topBgImage})` }">
            <view class="back-btn" @click="goBack">
                <image class="back-image" src="https://zero-one01.oss-cn-shenzhen.aliyuncs.com/icon/back.png"
                    mode="scaleToFill"></image>
            </view>
        </view>
        <!-- 预约试打表单区域 -->
        <view class="reservation-section">
            <view class="section-header">
                <text class="section-title">预约试打</text>
            </view>

            <!-- 试打地点 -->
            <view class="form-item row-layout">
                <text class="form-label-inline">试打地点</text>
                <view class="form-value-container">
                    <view class="form-value-inline">
                        <picker mode="selector" :value="selectedLocationIndex" :range="locations"
                            @change="handleLocationChange">
                            <text>{{ locations[selectedLocationIndex] || '请选择试打地点' }}</text>
                        </picker>
                    </view>
                </view>
            </view>

            <!-- 手机号输入框 -->
            <view class="form-item row-layout">
                <text class="form-label-inline">手机号</text>
                <view class="form-value-container">
                    <input class="form-input" type="number" placeholder="请输入手机号" v-model="phoneNumber"
                        @input="handlePhoneInput" />
                </view>
            </view>

            <view class="form-item">
                <button class="reservation-btn" :disabled="!isValidPhone" @click="submitReservation">
                    一键预约
                </button>
            </view>
            <text class="reservation-tip">预约成功后，将由公司顾问联系您确认具体试打行程</text>
        </view>
    </view>
</template>
  
<script>
export default {
    data() {
        return {
            topBgImage: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/icon/yuyueshidabg.png',
            locations: ['ZeroOne体育用品（惠城店）', '上海店', '广州店', '深圳店'],
            selectedLocationIndex: 0, // 默认选中第一个地点（视为有效）
            phoneNumber: '',
            isValidPhone: false
        };
    },
    methods: {
        goBack() {
            uni.navigateBack();
        },
        handleLocationChange(e) {
            this.selectedLocationIndex = e.target.value;
        },
        handlePhoneInput(e) {
            this.phoneNumber = e.detail.value;
            // 手机号正则验证（1开头，11位数字）
            this.isValidPhone = /^1[3-9]\d{9}$/.test(this.phoneNumber);
        },
        submitReservation() {
            if (this.selectedLocationIndex !== -1 && this.isValidPhone) { // 可根据需求调整是否允许默认选中
                console.log('预约提交成功，试打地点：', this.locations[this.selectedLocationIndex]);
                console.log('手机号：', this.phoneNumber);
                uni.navigateTo({
                    url: '/pages/index/reservationSuccess'
                })
                // 调用接口提交预约逻辑
            } else {
                uni.showToast({
                    title: '请完善表单信息',
                    icon: 'none',
                    duration: 1500
                });
            }
        }
    }
};
</script>
  
<style scoped>
.page-container {
    background-color: #000;
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
}

.top-image-section {
    position: relative;
    height: 400px;
    background-size: cover;
    background-position: center;
}

.back-btn {
    position: absolute;
    top: 80rpx;
    left: 20rpx;
    z-index: 10;
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;
    overflow: hidden;
}

.back-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 预约表单区域 - 灰色背景 */
.reservation-section {
    padding: 25px;
    background-color: rgba(255, 255, 255, 0.1);
    /* 灰色背景 */
    border-radius: 15px;
    margin: 20px;
}

.section-header {
    margin-bottom: 30px;
    /* 增加标题下方间距 */
}

.section-title {
    font-size: 24px;
    font-weight: bold;
}

/* 表单行 - 增加上下间距 */
.form-item {
    margin-bottom: 30px;
    /* 增加间距 */
}

.row-layout {
    display: flex;
    align-items: center;
}

.form-label-inline {
    font-size: 16px;
    color: #ccc;
    margin-right: 15px;
    white-space: nowrap;
    width: 60px;
    /* 固定标签宽度 */
}

/* 表单值容器 - 靠右对齐 */
.form-value-container {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.form-value-inline {
    font-size: 16px;
    text-align: right;
    /* 文本靠右对齐 */
}

/* 手机号输入框样式 */
.form-input {
    border-radius: 5px;
    color: white;
    text-align: right;
    /* 输入内容靠右对齐 */
    width: 100%;
    box-sizing: border-box;
}

.reservation-btn {
    width: 100%;
    background-color: rgba(23, 98, 238, 0.863);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 20px;
    cursor: pointer;
}

.reservation-btn:disabled {
    background-color: #999;
    cursor: not-allowed;
}

.reservation-tip {
    font-size: 13px;
    color: #ccc;
    text-align: center;
}
</style>